package com.infore.airsupervise.ui.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.infore.airsupervise.R;
import com.infore.airsupervise.adapter.PhotoAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.finalteam.galleryfinal.model.PhotoInfo;

/**
 * 展示照片的Fragment
 */
public class ShowPhotoFragment extends BaseFragment {

    @BindView(R.id.show_photo_recycler_view)
    RecyclerView recyclerView;

    private int itemWidth;      // item高度
    private List<PhotoInfo> photos;
    private PhotoAdapter photoAdapter;

    public ShowPhotoFragment() {
        // Required empty public constructor
    }

    @SuppressLint("ValidFragment")
    public ShowPhotoFragment(List<String> pathArr, int itemWidth) {
        this.itemWidth = itemWidth;
        photos = new ArrayList<>();
        for (String path : pathArr) {
            PhotoInfo pi = new PhotoInfo();
            pi.setPhotoPath(path);
            photos.add(pi);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_show_photo, container, false);
        unbinder = ButterKnife.bind(this, view);

        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recyclerView.setLayoutManager(linearLayoutManager);

        //设置适配器
        photoAdapter = new PhotoAdapter(photos, itemWidth);
        recyclerView.setAdapter(photoAdapter);

        return view;
    }

}
